package com.uyayo.portal.context.config;

import com.uyayo.portal.freemarker.*;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import com.jagregory.shiro.freemarker.ShiroTags;

import freemarker.template.Configuration;

@Component
@org.springframework.context.annotation.Configuration
public class FreeMarkerConfig implements InitializingBean{

	@Autowired
    private Configuration configuration;

	@Override
	public void afterPropertiesSet() {
		// 加上这句后，可以在页面上使用shiro标签
		configuration.setSharedVariable("shiro", new ShiroTags());
		configuration.setSharedVariable("dictionary", dictionaryDirective());
		configuration.setSharedVariable("cms_channel", cmsChannelDirective());
		configuration.setSharedVariable("cms_article", cmsActicleDirective());
		configuration.setSharedVariable("cms_ad", cmsAdDirective());
		configuration.setSharedVariable("cms_ad_list", cmsAdListDirective());
		configuration.setSharedVariable("cms_link_list", cmsLinkListDirective());
	}

	@Bean
	public DictionaryDirective dictionaryDirective(){
		return new DictionaryDirective();
	}
	@Bean
	public CmsChannelDirective cmsChannelDirective(){
		return new CmsChannelDirective();
	}
	@Bean
	public CmsActicleDirective cmsActicleDirective(){
		return new CmsActicleDirective();
	}

	@Bean
	public CmsAdDirective cmsAdDirective(){
		return new CmsAdDirective();
	}

	@Bean
	public CmsAdListDirective cmsAdListDirective(){
		return new CmsAdListDirective();
	}


	@Bean
	public CmsLinkListDirective cmsLinkListDirective(){
		return new CmsLinkListDirective();
	}
}